package com.deyuanyun.pic.settings.task;

import com.deyuanyun.pic.settings.enumeration.ThresholdType;
import com.deyuanyun.pic.settings.service.base.BizMsgSendService;
import com.deyuanyun.pic.settings.service.base.BizThresholdTaskService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.context.ServletContextAware;

import javax.servlet.ServletContext;

/**
 * 业务阀值任务调度初始化
 *
 * @author axiao(xj08.dream@gmail.com)
 * @version 1.0
 *          Histroy: [修改人][时间][描述]
 * @date 2016-06-17
 */
@Service
public class BizThresholdTaskInitializing implements ServletContextAware {

    private static final Logger LOGGER = LoggerFactory.getLogger(BizThresholdTaskInitializing.class);

    @Autowired BizMsgSendService bizMsgSendService;

    @Autowired BizThresholdTaskService bizThresholdTaskService;

    @Value("${jobPersistent}")
    private boolean jobPersistent = false; //是否持久化

    @Value("${dev_mod}")
    private boolean devMod = false;

    @Override
    public void setServletContext(ServletContext servletContext) {
        if (!jobPersistent) {//当不是持久化操作的时候手动去初始化任务调度出来
            bizThresholdTaskService.riskSystemCycle();//风险评价系统风险等级消息推送
            bizThresholdTaskService.pipeCycle(ThresholdType.RISK_PIPE_SCHEDULE.getValue());//风险评价管道周期提醒
            bizThresholdTaskService.pipeCycle(ThresholdType.INTERNAL_INSP_PIPE_SCHEDULE.getValue());//完整性评价内检测管道周期提醒
            bizThresholdTaskService.pipeCycle(ThresholdType.INTERNAL_EXTE_PIPE_SCHEDULE.getValue());//完整性评价外检测管道周期提醒任务调度
            bizThresholdTaskService.checkClientFailData();//检测客户端调用接口失败任务调度
        }
    }

}
